package com.kc.sjwh.service;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kc.sjwh.dao.RyDao;
import com.kc.sjwh.dao.UserDao;
import com.kc.sjwh.entity.po.Ry;
import com.kc.sjwh.entity.po.User;
import com.kc.sjwh.other.Page;
import com.kc.sjwh.other.QueryParam;

@Service
public class OutService {
	static Logger logger = Logger.getLogger(OutService.class);
	@Autowired
	UserDao userDao;
	@Autowired
	RyDao ryDao;
	

	/**
	 * 分页查询用户
	 * @param pageSize
	 * @param pageNum
	 * @param param
	 */
	public Page<User> userChooser_getPage(int pageSize, int pageNum, Map<String, String> param) {
		QueryParam q = new QueryParam(pageSize, pageNum).setOrder("cjsj desc, id");
		
		//添加动态的查询条件
		String v = null;
		v = param.get("startTime");
		if(StringUtils.isNotEmpty(v)) {
			q.addSqlCondition("cjsj >= to_date('"+v+"','yyyy-MM-dd hh24:mi')");
		}
		v = param.get("endTime");
		if(StringUtils.isNotEmpty(v)) {
			q.addSqlCondition("cjsj <= to_date('"+v+"','yyyy-MM-dd hh24:mi')");
		}
		v = param.get("keyword");
		if(StringUtils.isNotEmpty(v)) {
			q.addCondition("mc", "like", "%"+v+"%");
		}
		
		return userDao.getPage("get", q);
	}


	public Page<Ry> ryChooser_getPage(int pageSize, int pageNum, Map<String, String> param) {
		QueryParam q = new QueryParam(pageSize, pageNum).setOrder("cjsj desc, rybh");
		
		//添加动态的查询条件
		String v = null;
		v = param.get("keyword");
		if(StringUtils.isNotEmpty(v)) {
			q.addSqlCondition("ryxm like ? or ryjh like ?".replace("?", "'%"+v+"%'"));
		}
		
		return ryDao.getPage("get", q);
	}

	//根据ids获取人员s
	public List<Ry> getRysByIds(String ids) {
		return ryDao.getList(new QueryParam().addCondition("rybh", "in", ids.split(",")));
	}
}
